﻿using System;
using System.Web;
using System.Web.Mvc;

namespace Flagwind.Web.Plugins
{
	public class PluginRazorViewEngine : PluginViewEngine
	{
		#region 私有常量

		private readonly string[] FileExtensions = new[]
		{
			"cshtml",
			"vbhtml",
		};

		#endregion

		#region 构造方法

		public PluginRazorViewEngine(Flagwind.Plugins.PluginContext pluginContext) : base(pluginContext)
		{
			this.ViewExtensions = FileExtensions;
			this.PartialViewExtensions = FileExtensions;
			this.MasterExtensions = FileExtensions;
		}

		#endregion

		#region 创建视图

		protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
		{
			return new RazorView(controllerContext, viewPath, layoutPath: masterPath, runViewStartPages: true, viewStartFileExtensions: FileExtensions);
		}

		protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
		{
			return new RazorView(controllerContext, partialPath, layoutPath: null, runViewStartPages: false, viewStartFileExtensions: FileExtensions);
		}

		#endregion
	}
}

